package com.jp.knowledge.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.view.View;

import com.jp.knowledge.R;
import com.jp.knowledge.model.SearchKey;
import com.jp.knowledge.my.base.RecycleVAdapter;
import com.jp.knowledge.my.base.RecycleVHolder;

import java.util.List;

/**
 * Created by 528787067@qq.com on 2017/2/9.
 */

public class SearchHistoryAdapter extends RecycleVAdapter<SearchKey> implements RecycleVAdapter.OnItemClickListener, View.OnClickListener {

    public SearchHistoryAdapter(Context context, @NonNull List<SearchKey> list) {
        super(context, list);
        addItemClickListener(this);
    }

    @Override
    public int getLayoutId(int viewType) {
        return R.layout.dialog_team_circle_company_item;
    }

    @Override
    public void onBind(RecycleVHolder holder, int position) {
        holder.getConvertView().setBackground(mContext.getResources().getDrawable(R.drawable.normal_click_bg));
        holder.setTextView(R.id.company_name, getData(position).getName());
        holder.get(R.id.unselect_company).setTag(position);
        holder.get(R.id.unselect_company).setOnClickListener(this);
    }

    @Override
    public void itemSelect(int position) {
        if(this.itemActionHappen != null)
            this.itemActionHappen.onItemClick(position);
    }

    @Override
    public void onClick(View v) {
        if(this.itemActionHappen != null)
            this.itemActionHappen.onItemDelete((Integer) v.getTag());
    }

    private ItemActionHappen itemActionHappen;
    public void setItemActionHappen(ItemActionHappen itemActionHappen){
        this.itemActionHappen = itemActionHappen;
    }

    public interface ItemActionHappen{
        void onItemClick(int position);
        void onItemDelete(int position);
    }
}
